home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / pleas / ole / samples.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-06-13  |  8.6 KB  |  291 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "OA Samples"
  4.    ClientHeight    =   3675
  5.    ClientLeft      =   285
  6.    ClientTop       =   1215
  7.    ClientWidth     =   3690
  8.    Height          =   4080
  9.    Left            =   225
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3675
  12.    ScaleWidth      =   3690
  13.    Top             =   870
  14.    Width           =   3810
  15.    Begin TextBox Text1 
  16.       Height          =   1095
  17.       Left            =   1680
  18.       MultiLine       =   -1  'True
  19.       TabIndex        =   7
  20.       Text            =   "Text1"
  21.       Top             =   2520
  22.       Width           =   1935
  23.    End
  24.    Begin CommandButton Command7 
  25.       Caption         =   "Draw Stuff"
  26.       Height          =   375
  27.       Left            =   360
  28.       TabIndex        =   6
  29.       Top             =   3000
  30.       Width           =   1215
  31.    End
  32.    Begin CommandButton Command6 
  33.       Caption         =   "Word Dialog"
  34.       Height          =   375
  35.       Left            =   360
  36.       TabIndex        =   5
  37.       Top             =   2520
  38.       Width           =   1215
  39.    End
  40.    Begin CommandButton Command5 
  41.       Caption         =   "Solver"
  42.       Height          =   375
  43.       Left            =   360
  44.       TabIndex        =   4
  45.       Top             =   2040
  46.       Width           =   1215
  47.    End
  48.    Begin CommandButton Command4 
  49.       Caption         =   "Debug"
  50.       Height          =   375
  51.       Left            =   120
  52.       TabIndex        =   3
  53.       Top             =   120
  54.       Width           =   1215
  55.    End
  56.    Begin CommandButton Command3 
  57.       Caption         =   "Amortization"
  58.       Height          =   375
  59.       Left            =   360
  60.       TabIndex        =   2
  61.       Top             =   1560
  62.       Width           =   1215
  63.    End
  64.    Begin CommandButton Command2 
  65.       Caption         =   "XL Dialog"
  66.       Height          =   375
  67.       Left            =   360
  68.       TabIndex        =   1
  69.       Top             =   1080
  70.       Width           =   1215
  71.    End
  72.    Begin CommandButton Command1 
  73.       Caption         =   "XL Simple"
  74.       Height          =   375
  75.       Left            =   360
  76.       TabIndex        =   0
  77.       Top             =   600
  78.       Width           =   1215
  79.    End
  80. Sub Command1_Click ()
  81. ' 1. stuffs a label and some values in cells
  82. ' 2. creates a named range
  83. ' 3. creates a formula
  84. ' 4. and stores the Value in the VB variable foo
  85. ' Declarations
  86. Dim XL As object
  87. Dim APPXL As object
  88. Dim ws As object
  89. Dim cell As object
  90. ' Code
  91. Set XL = GetObject(, "Excel.Application")
  92. Set APPXL = XL.Application
  93. APPXL.Workbooks.Add
  94. Set ws = APPXL.ActiveSheet
  95. ws.Cells(1, 1).Value = "Test"
  96. ws.Cells(2, 1).Value = 100
  97. ws.Range("A2:A5").FillDown
  98. tmp = ws.Range("A1:B5").CreateNames(True, False, False, False)
  99. Set cell = ws.Range("A6")
  100. cell.FormulaR1C1 = "=SUM(Test)"
  101. foo = cell.Value
  102. Set cell = Nothing
  103. Set ws = Nothing
  104. Set XL = Nothing
  105. Set APPXL = Nothing
  106. End Sub
  107. Sub Command2_Click ()
  108. ' Calling an Excel dialog from VB
  109. ' 1. create an Excel workbook called SHEETS.XLS
  110. ' 2. open a dialog sheet
  111. ' 3. add a listbox
  112. Dim APPXL As object
  113. Dim XL As object
  114. Dim wb As object
  115. Dim dlg As object
  116. Dim dlgList As object
  117. Dim objList As object
  118. Set APPXL = GetObject(, "Excel.Application")
  119. Set XL = APPXL.Application
  120. XL.Workbooks.Open "C:\TEMP\TEST.XLS"
  121. Set wb = XL.ActiveWorkbook
  122. Set dlg = wb.DialogSheets("dialog1")
  123. Set dlgList = dlg.ListBoxes("SheetsList")
  124. Set objList = wb.Sheets
  125. dlgList.RemoveAllItems
  126. dlg.DialogFrame.Caption = "List of Sheets"
  127. For ix = 1 To objList.Count
  128.     dlgList.[AddItem] (objList(ix).Name)
  129. dlg.[Show]
  130. Set dlg = Nothing
  131. Set dlgList = Nothing
  132. Set objList = Nothing
  133. Set wb = Nothing
  134. Set XL = Nothing
  135. Set APPXL = Nothing
  136. End Sub
  137. Sub Command3_Click ()
  138. ' 1. opens AMORTIZE.XLS
  139. ' 2. plugs in values for the variables
  140. ' 3. and pops the calculated payment up in a message box
  141. '   C7  =Loan_amount
  142. '   C8  =Annual_interest_rate
  143. '   C9  =Term_in_years
  144. '   C10 =Payments_per_year
  145. '   C14 =Calculated_payment
  146. Dim APPXL As object
  147. Dim XL As object
  148. Dim ws As object
  149. Set APPXL = GetObject(, "Excel.Application")
  150. Set XL = APPXL.Application
  151. XL.Workbooks.Open "C:\WINDOWS\EXCEL\EXAMPLES\AMORT.XLS"
  152. Set ws = XL.ActiveSheet
  153. ws.Range("Loan_amount").Value = 100000
  154. ws.Range("Annual_interest_rate").Value = .075
  155. ws.Range("Term_in_years").Value = 30
  156. ws.Range("Payments_per_year").Value = 12
  157. MsgBox Format$(ws.Range("Calculated_payment").Value, "currency"), , "Payment"
  158. XL.Workbooks(1).[Close] (False)
  159. Set ws = Nothing
  160. Set XL = Nothing
  161. Set APPXL = Nothing
  162. End Sub
  163. Sub Command4_Click ()
  164. Dim XL As object
  165. Dim APPXL As object
  166. Dim ws As object
  167. Dim sheet As object
  168. Dim cell As object
  169. Dim zot As object
  170. Dim zot1 As object
  171. Dim zot2 As object
  172. Dim zot3 As object
  173. Dim zot4 As object
  174. Dim zot5 As object
  175. Print XL.Parent
  176. Print XL.Name
  177. Print ws.Range("Test").Value(3)
  178. Print ws.Selection
  179. Print ws.Parent.Name
  180. Print ws.Range("test").Parent.Name
  181. Print APPXL.Parent
  182. Print APPXL.Workbooks.Count
  183. Print APPXL.Worksheets.Count
  184. '====================================
  185. Print APPXL.Worksheets.Count
  186. '====================================
  187. Set XL = GetObject(, "Excel.Application")
  188. Set APPXL = XL.Application
  189. APPXL.WindowState = 3
  190. APPXL.Workbooks.Add
  191. Set ws = APPXL.ActiveSheet
  192. ws.Cells(1, 1).Value = "Test"
  193. ws.Cells(2, 1).Value = 100
  194. ws.Range("A2:A5").FillDown
  195. tmp = ws.Range("A1:B5").CreateNames(True, False, False, False)
  196. Set cell = ws.Range("A6")
  197. cell.FormulaR1C1 = "=SUM(Test)"
  198. Print cell.Value
  199. '=====================================
  200. ws.Range("Foo").Cells(1, 1).Value = 3
  201. Print ws.Cells(1, 1).Value
  202. End Sub
  203. Sub Command5_Click ()
  204. Dim APPXL As object
  205. Dim XL As object
  206. Dim ws As object
  207. Set APPXL = GetObject(, "Excel.Application")
  208. Set XL = APPXL.Application
  209. XL.Workbooks.Open "C:\WINDOWS\EXCEL\EXAMPLES\SOLVER\SOLVEREX.XLS"
  210. Set ws = XL.ActiveSheet
  211. oldP$ = ws.Range("$F$14").Value
  212. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.OK(!R10C6,1,0,)"
  213. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.ADD(!R10C6,1,""=40000"")"
  214. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.OK(!R14C6,1,0,(!R10C2:R10C5))"
  215. XL.ExecuteExcel4Macro "[SOLVER.XLA]SOLVER!SOLVER.SOLVE(True)"
  216. newP$ = ws.Range("$F$14").Value
  217. MsgBox "Old: " & Format(oldP$, "currency") & Chr$(10) & "New: " & Format(newP$, "currency"), , "Profit"
  218. XL.Workbooks(1).[Close] (False)
  219. Set ws = Nothing
  220. Set XL = Nothing
  221. Set APPXL = Nothing
  222. End Sub
  223. Sub Command6_Click ()
  224.     Dim doc As object
  225.     ' Copies the textbox into a new Word document
  226.     ClipBoard.SetText text1.Text
  227.     Set doc = CreateObject("word.basic")
  228.     doc.FileOpen "C:\TEMP\FOO.DOC"
  229.     doc.FileNewDefault
  230.     doc.EditPaste
  231.     ' Creates / overwrites a new Word macro "Counter"
  232.     doc.ToolsMacro "Counter", 0, 1
  233.     doc.EditSelectAll
  234.     doc.EditClear
  235.     doc.Insert "Sub MAIN"
  236.     doc.InsertPara
  237.     doc.Insert "ToolsWordCount"
  238.     doc.InsertPara
  239.     doc.Insert "Dim dlg As ToolsWordCount"
  240.     doc.InsertPara
  241.     doc.Insert "GetCurValues dlg"
  242.     doc.InsertPara
  243.     doc.Insert "MsgBox ""Current word count:"" + dlg.Words"
  244.     doc.InsertPara
  245.     doc.Insert "End Sub"
  246.     doc.FileClose 1
  247.     ' Runs the macro, manipulates the return message (a hack)
  248.     On Error Resume Next
  249.     doc.ToolsMacro "Counter", 1, 0
  250.     MsgBox Right$(Error$, Len(Error$) - 22)
  251.     ' Cleans up
  252.     doc.FileClose 2
  253.     Set doc = Nothing
  254. End Sub
  255. Sub Command7_Click ()
  256.     Dim appvisio As object
  257.     Dim obj1 As object
  258.     Dim obj2 As object
  259.     Dim obj3 As object
  260.     Dim obj4 As object
  261.     Dim obj5 As object
  262.     Set appvisio = CreateObject("visio.application")
  263.     Set obj1 = appvisio.Documents
  264.     obj1.Open ("c:\windows\visio\template\basic.vst")
  265.     Set obj1 = appvisio.ActiveDocument.Pages(1)
  266.     Set obj2 = appvisio.Documents(2)    ' Stencil sheet
  267.     Set obj3 = obj2.Masters             ' Collection of shapes
  268.     Set obj4 = obj3.Item(27)           ' Rectangle
  269.     Set obj5 = obj1.drop(obj4, 2, 5)
  270.     obj5.Text = "One"
  271.     Set obj5 = obj1.drop(obj4, 4, 5)
  272.     obj5.Text = "Two"
  273.     Set obj5 = obj1.drop(obj4, 6, 5)
  274.     obj5.Text = "Three"
  275.     Set obj5 = obj1.drop(obj4, 4, 7)
  276.     obj5.Text = "Main"
  277.     Set obj4 = obj3.Item(21)           ' Top to Bottom
  278.     Set obj5 = obj1.drop(obj4, 4.5, 6)
  279.     obj5.SetEnd 2, 2
  280.     Set obj5 = obj1.drop(obj4, 4.5, 6)
  281.     obj5.SetEnd 4, 4
  282.     Set obj5 = obj1.drop(obj4, 4.5, 6)
  283.     obj5.SetEnd 6, 6
  284.     Set obj5 = Nothing
  285.     Set obj4 = Nothing
  286.     Set obj3 = Nothing
  287.     Set obj2 = Nothing
  288.     Set obj1 = Nothing
  289.     Set appvisio = Nothing
  290. End Sub
  291.